/*
  Copyright © 2010  Vinícius dos Santos Oliveira

      This file is part of Touché.

      Touché is free software: you can redistribute it and/or modify
      it under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

#ifndef TOUCHEELEMENT_H
#define TOUCHEELEMENT_H

#include <QUuid>
#include <QGraphicsItem>

namespace Touche
{

    class StageActor;
    class StageActorLink;
    class ColaborativeController;
    class ColaborativeManager;

    class Element: public QObject
    {
        friend class StageActor;
        friend class StageActorLink;
        friend class ColaborativeController;
        friend class ColaborativeManager;

        Q_OBJECT

    protected:
        const QUuid id;
        bool m_null;

    public:
        Element();
        virtual ~Element();
        virtual const QString &type() const = 0;
//        virtual Options flags() = 0;
        /*
          todo elemento deveria salvar seu conteúdo em um xml,
          e a xml é retornada através de uma string para o núcleo
          do Touché
          */
        virtual QString save() const;
        /*
          para que a gravação de dados seja eficiente, o elemento
          também deveria informar os arquivos que deseja guardar,
          para que o Touché coloque-os dentro do pacote .touchez
          */
        virtual QString files() const;
        /*
          os elementos também deveriam ter a capacidade de recuperar
          os dados gravados
          */
        virtual void load(const QString &xml, const QString &file);
        /*
          todo item deveria ser inicialmente nulo, e mesmo nulo os métodos
          usados para salvar e carregar em/de arquivos deveriam ser funcionais,
          criando itens também nulos.
          */
        bool isNull();
        /*
          O elemento deveria retornar um QGraphicsItem cujo pai seja parentItem e
          essa é a única restrição que há.
          */
        virtual QRectF item(QGraphicsItem *parentItem) const = 0;
        virtual QVector<QString> menuOptions() const = 0;

    public slots:
        virtual void onMenuActived(const QString &option) = 0;
        virtual void onSceneReceived(QGraphicsScene *scene);
        virtual void onElementLocked(bool locked); // TODO

    signals:
        void menuUpdated(QVector<QString>);
        void lockElement(bool lock = true);
        void sceneRequest();
        void stageRequest();
        void contentsChanged(); // TODO
        void itemBoundingRectChanged(QRectF);
    };
} // namespace Touche

//Q_DECLARE_OPERATORS_FOR_FLAGS(Touche::Element::Options)

inline Touche::Element::Element() :
        id(QUuid::createUuid()),
        m_null(true)
{}

inline Touche::Element::~Element()
{}

inline QString Touche::Element::save() const
{
    //TODO: salvar a id
    return QString();
}

inline void Touche::Element::load(const QString &, const QString &)
{
}

inline QString Touche::Element::files() const
{
    return QString();
}

inline bool Touche::Element::isNull()
{
    return m_null;
}

inline void Touche::Element::onSceneReceived(QGraphicsScene *)
{
    return;
}

inline void Touche::Element::onElementLocked(bool)
{
    return;
}

#endif // TOUCHEELEMENT_H
